home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_actor_aigrenade.cog < prev    next >
Text File  |  1999-11-15  |  4KB  |  187 lines

  1. # ===================================================================
  2. # Jones 3D Cog Script
  3. #
  4. # actor_AIGrenade.cog
  5. #
  6. # [RandyT]
  7. #
  8. # Actor script for any AI with grenades.
  9. #
  10. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  11. # ===================================================================
  12.  
  13. symbols
  14.  
  15. message        created
  16. message        damaged
  17. message        killed
  18. message        callback
  19. message        timer
  20.  
  21. # ************************** TEMPLATES *************************
  22. template    tplWeap=grenade                local
  23. template    tplPoisonKit=poisonkit        local
  24. template    tplHealthKit=hlthsml        local
  25. template    tplFire=+bazooka_exp_fire    local
  26. template    tplSmoke=+bazooka_exp_smoke    local
  27. template    tplSparks=lavadeathsparks    local
  28.  
  29. # ************************** AI VARS ***************************
  30. int            TIMER_ID_WAKEUP_NORMAL=0    local
  31. int            TIMER_ID_WAKEUP_AND_DIE=1    local
  32.  
  33. # ************************** MISC LOCAL VARS *******************
  34. thing        bandito                        local
  35. thing        indy                        local
  36. thing        powerup                        local
  37.  
  38. int            damageType                    local
  39. int            timerID                        local 
  40. int            index                        local
  41.  
  42. flex        indyHealth                    local
  43. flex        kitChance                    local
  44.  
  45. vector        dir                            local
  46. vector        randVec                        local
  47.  
  48. end
  49.  
  50. # ===================================================================
  51. code
  52.  
  53. # -------------------------------------------------------------------
  54. created:
  55.  
  56.     bandito = GetSenderRef();
  57.     indy = GetLocalPlayerThing();
  58.  
  59.     SetThingFireOffset(bandito, '0.015 0.01 0.045');
  60.  
  61.     AIEnableInstinct(bandito, "roam", 0);
  62.  
  63.     return;
  64.  
  65. # -------------------------------------------------------------------
  66. damaged:
  67.  
  68.     bandito = GetSenderRef();
  69.     damageType = GetParam(1);
  70.  
  71.     # Been punched?
  72.     if (damageType == 0x08)
  73.     {
  74.         if ((GetParam(0) < GetThingHealth(bandito)) && (GetParam(0) * 2) > GetThingHealth(bandito))
  75.         {
  76.             # Make sure thing's not already disabled
  77.             if (BitTest(GetActorFlags(bandito), 0x40008)) return;
  78.  
  79.             # Play dead
  80.             AIKnockOut(bandito, RandBetween(10, 30), TIMER_ID_WAKEUP_NORMAL);
  81.         }
  82.     }
  83.     # Jeep or MineCar hit us
  84.     else if (damageType == 0x02000000)
  85.     {
  86.         # If invulnerable or immobile, ignore -- avoids multiple collision problem
  87.         if (BitTest(GetActorFlags(bandito), 0x40008))
  88.         { 
  89.             ReturnEx(0);
  90.             return;
  91.         }
  92.         else if (GetParam(0) >= GetThingHealth(bandito))
  93.         {
  94.             # long enough to land
  95.             AIRunOver(bandito, RandBetween(5, 6), TIMER_ID_WAKEUP_AND_DIE);
  96.             ReturnEx(0);
  97.             return;
  98.         }
  99.     }
  100.  
  101.     return;
  102.  
  103. # -------------------------------------------------------------------
  104. killed:
  105.  
  106.     bandito = GetSenderRef();
  107.  
  108.     # Killed by lava?
  109.     if (GetParam(1) == 0x200)
  110.     {
  111.         Sleep(0.1);
  112.         CreateThing(tplFire, bandito);
  113.         Sleep(0.3);
  114.         CreateThing(tplSmoke, bandito);
  115.         SetThingFlags(bandito, 0x80000);
  116.  
  117.         for (index = 0; index < 10; index = index + 1)
  118.         {
  119.             CreateThing(tplSparks, bandito);
  120.             Sleep(0.03);
  121.         }
  122.     }
  123.     else
  124.     {
  125.         # Create a health or snake bite kit, else just drop a grenade
  126.         indyHealth = GetThingHealth(indy);
  127.         if (indyHealth >= 750.0) kitChance = 0.05; 
  128.         else if (indyHealth >= 500.0) kitChance = 0.1;
  129.         else if (indyHealth >= 250.0) kitChance = 0.15;
  130.         else kitChance = 0.25;
  131.  
  132.         if (Rand() <= kitChance)
  133.         {
  134.             if ((BitTest(GetActorFlags(indy), 0x2000)) && (Rand() > 0.25))
  135.             {
  136.                 powerup = CreateThing(tplPoisonKit, bandito);
  137.             }
  138.             else
  139.             {
  140.                 powerup = CreateThing(tplHealthKit, bandito);
  141.             }
  142.         }
  143.         else
  144.         {
  145.             powerup = CreateThing(tplWeap, bandito);
  146.         }
  147.  
  148.         # Push it away a little...
  149.         dir = VectorTransformToOrient(bandito, '-0.17 0.0 0.0');
  150.         randVec = VectorSet(0, Rand() * 360, 0);
  151.         dir = VectorRotate(dir, randVec);
  152.         SetThingVel(powerup, dir);
  153.     }
  154.  
  155.     return;
  156.  
  157.  
  158. # -------------------------------------------------------------------
  159. callback:
  160.  
  161.     bandito = GetSenderRef();
  162.  
  163.     if (GetParam(1) == 21) SetWeaponModel(bandito, 11);
  164.     else ResetWeaponModel(bandito);
  165.  
  166.     return;
  167.  
  168. # -------------------------------------------------------------------
  169. timer:
  170.  
  171.     bandito = GetParam(0);
  172.     timerID = GetSenderId();
  173.     if (timerID == TIMER_ID_WAKEUP_NORMAL) # was knocked out but not killed
  174.     {
  175.         AIKnockOut(bandito, 0, TIMER_ID_WAKEUP_NORMAL);
  176.         SetHealth(bandito, 100.0);
  177.     }
  178.     else if (timerID == TIMER_ID_WAKEUP_AND_DIE)
  179.     {
  180.         ClearActorFlags(bandito, 0x8); # make sure not invulnerable
  181.         DamageThing(bandito, GetThingMaxHealth(bandito), 0x1, GetLocalPlayerThing()); # using impact damage to avoid infinite loop
  182.     }
  183.  
  184.     return;
  185.  
  186. end
  187.